﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage"
    Theme="Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    AptitudeForm
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        function DisableControls() {
            $(".disabled").each(function () {
                $(this).find("input,textarea").attr("readonly", "readonly");
            })
        }

        function MedicalAdvices_OnRowSelected(e) {
            var medicalAdviceID = e.row.cells[0].innerHTML;
            var radio = $(e.row).find("input[type='radio']");
            radio.click();
        }

        function Recomandations_OnRowSelected(e) {
            var recomandationID = e.row.cells[0].innerHTML;
            var checkbox = $(e.row).find("input[type='checkbox']");
            if (checkbox.attr("checked") != true) {
                checkbox.attr("checked", "true");
            }
            else {
                checkbox.removeAttr("checked");
            }
        }

        function Company_OnComboBoxChange(e) {
            var form = $("#companyForm");
            SubmitForm(form, "DisableControls()", true);
        }

        function checkAllEmployees(sender) {
            var checkState = $(sender).is(":checked");
            $("#Employees").find("input[type='checkbox']").each(function () {
                $(this).attr("checked", checkState);
            });
        }

        function checkAllExaminations(sender) {
            var checkState = $(sender).is(":checked");
            $("#Examinations").find("input[type='checkbox']").each(function () {
                $(this).attr("checked", checkState);
                $(this).attr("value", checkState);
            });
        }

        function createExaminations() {
            var form = $("#companyForm");
            $("#Employees").find("input[type=hidden][name^='Employee']").remove();
            form.find("#Action").val("CreateExaminations");
            SubmitForm(form, "", true);
        }

        function printExaminations() {
            var form = $("#companyForm");
            form.find("#Action").val("StoreExaminations");
            $("#Examinations").find("input[type=hidden][name^='Examination']").remove();
            $("#Recomandations").find("input[type=hidden][name^='Recomandation']").remove();
            var callback = "openPrintWindow('" + '<%: Url.Action("PrintExaminations") %>' + "')";
            PostForm(form, callback);
        }

        function onExaminationDateChanged() {
            var form = $("#companyForm");
            var datePicker = form.find("#ExaminationsDate").data("tDatePicker");
            var allExaminations;
            if (form.find("#AllExaminationsAll").attr("checked")) {
                datePicker.disable();
                allExaminations = true;
            }
            else {
                datePicker.enable();
                allExaminations = false;
            }

            var companyID = form.find("#CompanyID").data("tComboBox").value();
            var selectedDate = datePicker.value();
            var targetArea = form.find("#examinationsList");
            ShowLoader(targetArea);
            $.ajax({ type: "POST",
                url: '<%: Url.Action("LoadExaminations", "Application") %>' + "?companyID=" + companyID + "&allExaminations=" + allExaminations + "&year="+ selectedDate.getYear() + "&month=" + (selectedDate.getMonth() + 1) + "&day=" + selectedDate.getDate(),
                dataType: "application/JSON",
                success: function (result) {
                    targetArea.html(result);
                }   
            });
        }
    </script>
    <h2>
        <%: Resources.Global.AptitudeFormPageTitle %>
    </h2>
    <%: Html.ValidationSummary(true) %>
    <% using (Ajax.BeginForm("CompanyView", null, null, new { id = "companyForm" }))
       {%>
    <% Html.RenderAction("CompanyView"); %>
    <% } %>
    <% Html.Telerik().ScriptRegistrar().DefaultGroup(group => group
       .Add("telerik.common.min.js")
       .Add("telerik.grid.min.js")
       .Add("telerik.calendar.min.js")
       .Add("telerik.datepicker.min.js")
       .Add("telerik.grid.filtering.js")); 
    %>
</asp:Content>
